<?php
if (!function_exists( 'array_change_key_case' )) {
	if (!defined('CASE_LOWER')) {
		define('CASE_LOWER', 0);
	}
	if (!defined('CASE_UPPER')) {
		define('CASE_UPPER', 1);
	}
	function array_change_key_case( $input, $case=CASE_LOWER ) {
		if (!is_array( $input )) {
			return false;
		}
		$array = array();
		foreach ($input as $k=>$v) {
			if ($case) {
				$array[strtoupper( $k )] = $v;
			} else {
				$array[strtolower( $k )] = $v;
			}
		}
		return $array;
	}
}


if (!function_exists('file_get_contents')) {
	function file_get_contents($filename, $incpath = false, $resource_context = null)
	{
		if (false === $fh = fopen($filename, 'rb', $incpath)) {
			trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
			return false;
		}

		clearstatcache();
		if ($fsize = @filesize($filename)) {
			$data = fread($fh, $fsize);
		} else {
			$data = '';
			while (!feof($fh)) {
				$data .= fread($fh, 8192);
			}
		}

		fclose($fh);
		return $data;
	}
}


if (!function_exists('file_put_contents')) {
	function file_put_contents($filename, $content, $flags = null, $resource_context = null)
	{
		// If $content is an array, convert it to a string
		if (is_array($content)) {
			$content = implode('', $content);
		}

		// If we don't have a string, throw an error
		if (!is_scalar($content)) {
			trigger_error('file_put_contents() The 2nd parameter should be either a string or an array', E_USER_WARNING);
			return false;
		}

		// Get the length of date to write
		$length = strlen($content);

		// Check what mode we are using
		$mode = ($flags & FILE_APPEND) ?
					$mode = 'a' :
					$mode = 'w';

		// Check if we're using the include path
		$use_inc_path = ($flags & FILE_USE_INCLUDE_PATH) ?
					true :
					false;

		// Open the file for writing
		if (($fh = @fopen($filename, $mode, $use_inc_path)) === false) {
			trigger_error('file_put_contents() failed to open stream: Permission denied', E_USER_WARNING);
			return false;
		}

		// Write to the file
		$bytes = 0;
		if (($bytes = @fwrite($fh, $content)) === false) {
			$errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s',
							$length,
							$filename);
			trigger_error($errormsg, E_USER_WARNING);
			return false;
		}

		// Close the handle
		@fclose($fh);

		// Check all the data was written
		if ($bytes != $length) {
			$errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.',
							$bytes,
							$length);
			trigger_error($errormsg, E_USER_WARNING);
			return false;
		}

		// Return length
		return $bytes;
	}
}


if (!function_exists('dir_list')) {
	function dir_list($path) {
		$list_ignore = array ('.','..','index.html');
		$handle=opendir($path);
		
		$i=1;
		while ($file = readdir($handle)) {
			if (is_file($path . $file) && !in_array($file,$list_ignore)) {
				$fileList[$i]=$file;
				$i++;
			}
		}
		closedir($handle);
		return ((isset($fileList)) ? $fileList : null);
	}
}


if(!function_exists('redirect')){
function redirect($link,$sec=0) {
	if($sec==0) {
		echo "<script language=\"javascript\">location.href='".$link."';</script>";
	}else{
		echo "<html><head><meta http-equiv='refresh' content='".$sec.";url=".$link."'></head></html>";
	}
}
}


if(!function_exists('tplredirect')){
function tplredirect($link,$sec=0) {
	return "<html><head><meta http-equiv='refresh' content='".$sec.";url=".$link."'></head></html>";
}
}


if(!function_exists('msgbox')){
function msgbox($message) {
	echo "<script language=\"javascript\">window.alert(\"" . $message . "\");</script>";
	/*echo "<script language=\"javascript\">if(e('message')==undefined) e('right_container').innerHTML = '<div id=\"message\" style=\" display:block;  padding:10px; background:#069; color:#FFF; border:#036 solid 1px; margin:10px; text-align:center; font-size:14px;\">".$message."</div>' + e('right_container').innerHTML; else e('message').innerHTML='".$message."';</script>";
    /*echo "<div id=\"message\" style=\" display:none;  padding:10px; background:#069; color:#FFF; border:#036 solid 1px; margin:10px; text-align:center; font-size:14px;\">" . $message . "</div>";*/
}
}


if(!function_exists('half_string')){
function half_string($text, $maxlength)
{
	if(strlen($text)>$maxlength)
	{ $text=strip_tags(substr($text,0,$maxlength),"<font>,<div>,<b>,<i>,<u>,<br />,<img />")." ..."; }
	
	return $text;
}
}


if(!function_exists('thumbnail')){
function thumbnail($lokasi, $maxres) {
	if(!file_exists($lokasi)){ return "File Not Found!!"; exit; }
	$info=getimagesize($lokasi); $res2=$info[0]; $res1=$info[1];
		
	if($res1>$maxres || $res2>$maxres)
	{
		if($res1>$res2)
		{
			$lb=floor($res2*$maxres/$res1);
			$pj=$maxres;
		}else
		{
			$pj=floor($res1*$maxres/$res2);
			$lb=$maxres;
		}
	}else
	{
		$pj=$res1;
		$lb=$res2;
	}
	
	$tpl="<img src=\"".$lokasi."\" width=\"".$lb."\" height=\"".$pj."\" alt=\"\" /><br />
		<font size=\"1\" color=\"navy\"  face=\"Verdana, Arial, Helvetica, sans-serif\">".$res2."x".$res1." pixels<br />";

	return $tpl;
}
}


if(!function_exists('nvl')){
function nvl($val, $alt){
	if($val == NULL || strlen($val)==0){
		return $alt;
	}
	
	return $val;
}
}


if(!function_exists('stringFileSize')){
function stringFileSize($size) {
	$satuan = 'bytes';
	if($size>1024) {
		$size	= ceil($size/1024);
		$satuan	= 'kB';
	}
	if($size>1024) {
		$size	= round($size/1024, 2);
		$satuan	= 'MB';
	}
	if($size>1024) {
		$size	= round($size/1024, 2);
		$satuan	= 'GB';
	}
	return $size.' '.$satuan;
}
}


if(!function_exists('server_OS')){
function server_OS($param="default") {
	return ($param=="default") ? defineOS(strtolower(php_uname("s")." ".php_uname("r"))) : php_uname("a");
}
}


if(!function_exists('client_ip')){
function client_ip() {
	$ipclient = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : getenv('REMOTE_ADDR') );
	return $ipclient;
}
}


function client_OS() {
	return defineOS(strtolower(getenv("HTTP_USER_AGENT")));
}


function client_browser() {
	return defineBrowser(getenv("HTTP_USER_AGENT"));
}


function defineOS($source) {
	$result = "";
	$osAlias = array (
		array('windows nt 6.8'	, 'Windows 8'),
		array('windows nt 6.1'	, 'Windows 7'),
		array('windows nt 6.0'	, 'Windows Vista'),
		array('windows nt 5.2'	, 'Windows 2003'),
		array('windows nt 5.0'	, 'Windows 2000'),
		array('windows nt 5.1'	, 'Windows XP'),
		array('winnt' 			, 'Windows NT'),
		array('winnt 4.0' 		, 'Windows NT'),
		array('windows 98' 		, 'Windows 98'),
		array('win98' 			, 'Windows 98'),
		array('windows 95' 		, 'Windows 95'),
		array('win95' 			, 'Windows 95'),
		array('sunos' 			, 'Sun Solaris'),
		array('freebsd' 		, 'FreeBSD'),
		array('ppc' 			, 'Macintosh'),
		array('mac os x' 		, 'Mac OS X'),
		array('linux' 			, 'Linux'),
		array('debian' 			, 'Debian'),
		array('beos' 			, 'BeOS'),
		array('winnt4.0' 		, 'Windows NT 4.0'),
		array('apachebench' 	, 'ApacheBench'),
		array('aix' 			, 'AIX'),
		array('irix' 			, 'Irix'),
		array('osf' 			, 'DEC OSF'),
		array('hp-ux' 			, 'HP-UX'),
		array('netbsd' 			, 'NetBSD'),
		array('bsdi' 			, 'BSDi'),
		array('openbsd' 		, 'OpenBSD'),
		array('gnu' 			, 'GNU/Linux'),
		array('unix' 			, 'Unknown Unix system')
	);
	
	$definedOS=false;
	for($i=0;$i<count($osAlias);$i++)
	{
		if(strstr(strtolower($source),$osAlias[$i][0])!="" && !$definedOS)
		{ $result=$osAlias[$i][1]; $definedOS=true; }
	}
	if($result=="") $result=php_uname("a");
	
	return $result;
}


function defineBrowser($source,$createLog=false) {
	$result = "";
	$browsersAlias = array (
		array('icab'			, 'iCab'),
		array('go!zilla'		, 'Go!Zilla'),
		array('konqueror'		, 'Konqueror'),
		array('links'			, 'Links'),
		array('lynx'			, 'Lynx'),
		array('omniweb'			, 'OmniWeb'),
		array('opera'			, 'Opera'),
		array('msie 6.0'		, 'Microsoft Internet Explorer 6.0'),
		array('msie'			, 'Microsoft Internet Explorer'),
		array('apachebench'		, 'ApacheBench'),
		array('wget'			, 'Wget'),
		array('22acidownload'	, '22AciDownload'),
		array('aol\\-iweng'		, 'AOL-Iweng'),
		array('amaya'			, 'Amaya'),
		array('amigavoyager'	, 'AmigaVoyager'),
		array('aweb'			, 'AWeb'),
		array('bpftp'			, 'BPFTP'),
		array('chimera'			, 'Chimera'),
		array('cyberdog'		, 'Cyberdog'),
		array('dillo'			, 'Dillo'),
		array('dreamcast'		, 'Dreamcast'),
		array('downloadagent'	, 'DownloadAgent'),
		array('ecatch'			, 'eCatch'),
		array('emailsiphon'		, 'EmailSiphon'),
		array('encompass'		, 'Encompass'),
		array('friendlyspider'	, 'FriendlySpider'),
		array('fresco'			, 'ANT Fresco'),
		array('galeon'			, 'Galeon'),
		array('getright'		, 'GetRight'),
		array('headdump'		, 'HeadDump'),
		array('hotjava'			, 'Sun HotJava'),
		array('ibrowse'			, 'IBrowse'),
		array('intergo'			, 'InterGO'),
		array('k-meleon'		, 'K-Meleon'),
		array('linemodebrowser'	, 'W3C Line Mode Browser'),
		array('lotus-notes'		, 'Lotus Notes web client'),
		array('macweb'			, 'MacWeb'),
		array('multizilla'		, 'MultiZilla'),
		array('ncsa_mosaic'		, 'NCSA Mosaic'),
		array('netpositive'		, 'NetPositive'),
		array('nutscrape'		, 'Nutscrape'),
		array('msfrontpageexpress'	, 'MS FrontPage Express'),
		array('phoenix'			, 'Phoenix'),
		array('firebird'		, 'Mozilla Firebird'),
		array('firefox'			, 'Mozilla Firefox'),
		array('safari'			, 'Safari'),
		array('tzgeturl'		, 'TzGetURL'),
		array('viking'			, 'Viking'),
		array('webfetcher'		, 'WebFetcher'),
		array('webexplorer'		, 'IBM-WebExplorer'),
		array('webmirror'		, 'WebMirror'),
		array('webvcr'			, 'WebVCR'),
		// Site grabbers
		array('teleport'		, 'TelePort Pro'),
		array('webcapture'		, 'Acrobat'),
		array('webcopier'		, 'WebCopier'),
		// Music only browsers
		array('real'			, 'RealAudio or compatible (media player)'),
		array('winamp'			, 'WinAmp (media player)'),				// Works for winampmpeg and winamp3httprdr
		array('windows-media-player'	, 'Windows Media Player (media player)'),
		array('audion'			, 'Audion (media player)'),
		array('freeamp'			, 'FreeAmp (media player)'),
		array('itunes'			, 'Apple iTunes (media player)'),
		array('jetaudio'		, 'JetAudio (media player)'),
		array('mint_audio'		, 'Mint Audio (media player)'),
		array('mpg123'			, 'mpg123 (media player)'),
		array('nsplayer'		, 'NetShow Player (media player)'),
		array('sonique'			, 'Sonique (media player)'),
		array('uplayer'			, 'Ultra Player (media player)'),
		array('xmms'			, 'XMMS (media player)'),
		array('xaudio'			, 'Some XAudio Engine based MPEG player (media player)'),
		// PDA/Phonecell browsers
		array('alcatel'			, 'Alcatel Browser (PDA/Phone browser)'),
		array('ericsson'		, 'Ericsson Browser (PDA/Phone browser)'),
		array('mot-'			, 'Motorola Browser (PDA/Phone browser)'),
		array('nokia'			, 'Nokia Browser (PDA/Phone browser)'),
		array('panasonic'		, 'Panasonic Browser (PDA/Phone browser)'),
		array('philips'			, 'Philips Browser (PDA/Phone browser)'),
		array('sonyericsson'		, 'Sony/Ericsson Browser (PDA/Phone browser)'),
		array('mmef'			, 'Microsoft Mobile Explorer (PDA/Phone browser)'),
		array('mspie'			, 'MS Pocket Internet Explorer (PDA/Phone browser)'),
		array('wapalizer'		, 'WAPalizer (PDA/Phone browser)'),
		array('wapsilon'		, 'WAPsilon (PDA/Phone browser)'),
		array('webcollage'		, 'WebCollage (PDA/Phone browser)'),
		array('up\.'			, 'UP.Browser (PDA/Phone browser)'),					// Works for UP.Browser and UP.Link
		// PDA/Phonecell I-Mode browsers
		array('docomo'			, 'I-Mode phone (PDA/Phone browser)'),
		array('portalmmm'		, 'I-Mode phone (PDA/Phone browser)'),
		// Others (TV)
		array('webtv'			, 'WebTV browser'),
		// Other kind of browsers
		array('csscheck'		,  'WDG CSS Validator'),
		array('w3m'				, 'w3m'),
		array('w3c_css_validator', 'W3C CSS Validator'),
		array('w3c_validator'	, 'W3C HTML Validator'),
		array('wdg_validator'	,  'WDG HTML Validator'),
		array('webzip'			, 'WebZIP'),
		array('staroffice'		, 'StarOffice'),
		array('libwww'			, 'LibWWW'),
		array('netscape'		, 'Netscape'),
	);
	
	$definedBrowser=false;
	for($i=0;$i<count($browsersAlias);$i++)
	{
		if(strstr(strtolower($source),$browsersAlias[$i][0])!="" && !$definedBrowser)
		{ $result=$browsersAlias[$i][1]; $definedBrowser=true; }
	}
	if($result=="")
	{
		if((ereg("Nav", $source)) || (ereg("Gold", $source)) || 
		(ereg("X11", $source)) || (ereg("Mozilla", $source))) 
		$result = "mozilla";
		else $result = "oth";
	}
		
	return $result;
}


function generate_captcha_code() {
	$arr_text = array(	'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 
						'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 
						'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7',
						'8', '9');
	$max = count($arr_text) - 1;
	$ls_code	= '';
	for($i=0; $i<5; $i++) {
		$index		=	rand(0, $max);
		$ls_code	.=	$arr_text[$index];
	}
	
	$requestId	= md5(client_ip() . now() . $index);
	
	return array('requestId' => $requestId, 'code' => $ls_code);
}


function fm_message_view($message, $smileys) {
	$message = htmlentities($message);
	
	// Replacing smileys
	if(count($smileys)>1) {
		foreach($smileys as $smiley) {
			$message=str_replace($smiley['CAR_REPLACE'], '<img src="includes/images/smileys/'.$smiley['SMILEY'].'" alt="" border="" />', $message);
		}
	}
	
	//Replacing BBcode
	$message=str_replace('[br /]','<br />',$message);
	$message=str_replace('[br/]','<br />',$message);
	$message=str_replace('[b]','<b>',$message);
	$message=str_replace('[/b]','</b>',$message);
	$message=str_replace('[i]','<i>',$message);
	$message=str_replace('[/i]','</i>',$message);
	$message=str_replace('[u]','<u>',$message);
	$message=str_replace('[/u]','</u>',$message);
	$message=str_replace("[color=darkred]", '<font color="darkred">',$message);
	$message=str_replace('[color=red]','<font color="red">',$message);
	$message=str_replace('[color=orange]','<font color="orange">',$message);
	$message=str_replace('[color=brown]','<font color="brown">',$message);
	$message=str_replace('[color=yellow]','<font color="yellow">',$message);
	$message=str_replace('[color=green]','<font color="green">',$message);
	$message=str_replace('[color=olive]','<font color="olive">',$message);
	$message=str_replace('[color=cyan]','<font color="cyan">',$message);
	$message=str_replace('[color=blue]','<font color="blue">',$message);
	$message=str_replace('[color=darkblue]','<font color="darkblue">',$message);
	$message=str_replace('[color=indigo]','<font color="indigo">',$message);
	$message=str_replace('[color=violet]','<font color="violet">',$message);
	$message=str_replace('[color=white]','<font color="white">',$message);
	$message=str_replace('[color=black]','<font color="black">',$message);
	$message=str_replace('[/color]','</font>',$message);
	$message=str_replace('[size=8]','<span style="font-size:8px;">',$message);
	$message=str_replace('[size=10]','<span style="font-size:10px;">',$message);
	$message=str_replace('[size=12]','<span style="font-size:12px;">',$message);
	$message=str_replace('[size=18]','<span style="font-size:18px;">',$message);
	$message=str_replace('[size=24]','<span style="font-size:24px;">',$message);
	$message=str_replace('[/size]','</span>',$message);
	$message=str_replace('[code]','<div class="code"><b>Code :</b><div>',$message);
	$message=str_replace('[/code]','</div></div>',$message);
	$message=str_replace('[quote]','<div class="quote"><b>Quote :</b><div>',$message);
	$message=str_replace('[/quote]','</div></div>',$message);
	$message=str_replace('[img]','<img src="',$message);
	$message=str_replace('[/img]','" class="imagelink" border="0" alt="" />',$message);
	
	return $message;
}

function js_asign($str) {
	//return str_replace( chr(10), '\\n', str_replace( chr(13), chr(10), str_replace('\n', chr(13), addslashes($str) ) ) ) ;
	return str_replace( chr(10), '\\n', str_replace( chr(13), '', str_replace('\n', '', addslashes($str) ) ) ) ;
}

function convert_sessionExpire($expired){
	$sec	= $expired - strtotime(now());
	return	(($sec>60) ? intval(floor($sec/60)).' minute ' : '') . intval($sec%60).' second';
}

function renderId($str){
	$arr_objName = explode('/', $str);
	$model = $arr_objName[0];
	$field = $arr_objName[1];
	unset($arr_objName);
	
	$arr_fieldName = explode('_', strtolower($field));
	$fieldName = '';
	for($i=0, $max_i=count($arr_fieldName); $i<$max_i; $i++) {
		$fieldName .= ucfirst($arr_fieldName[$i]);
	} unset($arr_fieldName);
	
	return $model . $fieldName;
}

function renderName($str){
	$arr_objName = explode('/', $str);
	$model 	= $arr_objName[0];
	$field	= strtolower( $arr_objName[1] );
	$add	= isset($arr_objName[2]) ? strtolower( $arr_objName[2] ) : '';
	unset($arr_objName);
	
	return 'data['.$model.']['.$field.']' . ($add!='' ? '['.$add.']' : '');
}

function show_keys($arr_input, $quote=''){
	$arr_key = array_keys($arr_input);
	for($i=0, $max_i=count($arr_key); $i<$max_i; $i++){
		echo ($i>0?', ':'') . $quote . $arr_key[$i] . $quote;
	}
}

function imageResize($source, $target=NULL, $maxwidth=150){
	

	$ext	= strtolower(end(explode('.',$source)));
	
	$fileinfo = @getimagesize($source);
	$width = $fileinfo[0]; $height	= $fileinfo[1];
	
	// Position
	if($width>$height) $position = 'L';
	else if($width<$height) $position = 'P';
	else $position = 'S';
	
	// Synchronize Picture Size
	if($position=='S'){ $width=$maxwidth; $height=$maxwidth; }
	else if($position == 'L'){
		$height	= ceil(($maxwidth/$width)*$height);
		$width	= $maxwidth;
	}else if($position == 'P'){
		$width	= ceil(($maxwidth/$height)*$width);
		$height	= $maxwidth;
	}
	
	if(!class_exists('WideImage')){
		include_once APPPATH."third_party/wideimage/WideImage.php";
	}
	
	$image = WideImage::load($source);
	$resized = $image->resize($width, $height);
	$resized->saveToFile($target);

	//load the big image
	/*if(in_array($ext, array('jpg', 'jpeg'))){
		$im=@imagecreatefromjpeg($source);
	}else if($ext=='gif'){
		$im=@imagecreatefromgif($source);
		
		//$transparent_index = @ImageColorTransparent($im);
        //if($transparent_index!=(-1)) $transparent_color = @ImageColorsForIndex($im,$transparent_index); 
		
		@imagealphablending($im, false);
		@imagesavealpha($im,true);
		$transparent = @imagecolorallocatealpha($im, 255, 255, 255, 127);
		@imagefilledrectangle($im, 0, 0, $height, $nHeight, $transparent);
	}else if($ext=='png'){
		$im=@imagecreatefrompng($source);
		//@ImageAlphaBlending($im,true);
        //@ImageSaveAlpha($im,true); 
		
		@imagealphablending($im, false);
		@imagesavealpha($im,true);
		$transparent = @imagecolorallocatealpha($im, 255, 255, 255, 127);
		@imagefilledrectangle($im, 0, 0, $height, $nHeight, $transparent);

	}else if($ext=='bmp'){
		$im=@imagecreatefromwbmp($source);
	}
	
	//create a new blank image for the thumbnail
	//$out=imagecreate($outputwidth,$h);
	if(in_array($ext, array('jpg', 'jpeg'))){
		$out=@ImageCreateTrueColor($width,$height);
	}else{
		$out=imagecreate($width,$height);
	}
	
	//copy and resize the large image to this
	@imagecopyresized($out,$im,0,0,0,0,$width,$height,$fileinfo[0],$fileinfo[1]);
	
	if(isset($target) && trim($target)!=''){
		//save the image so we don't need to recreate 
		//it next time
		if(in_array($ext, array('jpg', 'jpeg'))){
			@imagejpeg($out, $target);
		}else if($ext=='gif'){
			@imagegif($out, $target);
		}else if($ext=='png'){
			@imagepng($out, $target);
		}else if($ext=='bmp'){
			@imagewbmp($out, $target);
		}
	}else{
		//output the image
		if(in_array($ext, array('jpg', 'jpeg'))){
			@header("Content-type: image/jpeg");
		}else if($ext=='gif'){
			@header("Content-type: image/gif");
		}else if($ext=='png'){
			@header("Content-type: image/png");
		}else if($ext=='bmp'){
			@header("Content-type: image/bmp");
		}
		@header('Cache-Control: no-cache');
		@header("Pragma: no-cache");
		//imageinterlace($out, 100);
		@imagejpeg($out);
	}*/
	
}


function compressResponse($buffer) {
	/* remove comments */
	$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
	/* remove tabs, spaces, newlines, etc. */
	$buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
	return $buffer;
}

function numberDisplay($an_nilai, $precision=0){
	return number_format($an_nilai, $precision, ',', '.');
}

function numberValue($an_nilai){
	return (double)str_replace(',','',$an_nilai);
}


function GenerationCle($Texte,$CleDEncryptage) { 
	$CleDEncryptage = md5($CleDEncryptage); 
	$Compteur=0; 
	$VariableTemp = ""; 
	for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++) 
	{ 
		if ($Compteur==strlen($CleDEncryptage))
		$Compteur=0; 
		$VariableTemp.= substr($Texte,$Ctr,1) ^ substr($CleDEncryptage,$Compteur,1); 
		$Compteur++; 
	} 
	return $VariableTemp; 
} 

function encrypt($Texte,$Cle) { 
	srand((double)microtime()*1000000); 
	$CleDEncryptage = md5(rand(0,32000) ); 
	$Compteur=0; 
	$VariableTemp = ""; 
	for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++) 
	{ 
		if ($Compteur==strlen($CleDEncryptage)) 
		$Compteur=0; 
		$VariableTemp.= substr($CleDEncryptage,$Compteur,1).(substr($Texte,$Ctr,1) ^ substr($CleDEncryptage,$Compteur,1) ); 
		$Compteur++;
	} 
	return base64_encode(GenerationCle($VariableTemp,$Cle) );
} 

function decrypt($Texte,$Cle) { 
	$Texte = GenerationCle(base64_decode($Texte),$Cle);
	$VariableTemp = ""; 
	for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++) 
	{ 
		$md5 = substr($Texte,$Ctr,1); 
		$Ctr++; 
		$VariableTemp.= (substr($Texte,$Ctr,1) ^ $md5); 
	} 
	return $VariableTemp; 
}

function number_format3($ammount, $digit=2){
	if($ammount=='') $ammount = 0;
	return @number_format($ammount, $digit, ',', '.');
}

function toNumber($as_string){
	return str_replace(',','.',str_replace('.','',$as_string));
}
?>